//
//  M_PhotoViewController.m
//  Model
//
//  Created by apple on 2018/7/9.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "M_PhotoViewController.h"
#import "ZJScrollPageView.h"
#import "M_PhotoOneViewController.h"
#import "M_HomeSouSuoViewController.h"
#import "M_MineHelpZXViewController.h"//客服
@interface M_PhotoViewController ()<ZJScrollPageViewDelegate>
{
    
    NSInteger shouYeID;
    
}
@property(strong, nonatomic)NSArray<UIViewController<ZJScrollPageViewChildVcDelegate> *> *childVcs;
@property(strong, nonatomic) NSMutableArray *titles;
@property (weak, nonatomic) ZJScrollSegmentView *segmentView;
@property (weak, nonatomic) ZJContentView *contentView;
@property (nonatomic, strong) NSMutableArray *arrOfID;
@property (nonatomic, strong) NSMutableArray *arrOfName;



@end

@implementation M_PhotoViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    shouYeID = [[PublicFunction getConfigWithKey:@"shouYeID"] integerValue];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tongzhi:)name:@"tongzhi" object:nil];
    
    self.title = @"私照";
    UIImage *img = [UIImage imageNamed:@"search"];
    UIButton *rightButton=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, img.size.width, img.size.height)];
    [rightButton addTarget:self action:@selector(rightNavItemClick) forControlEvents:UIControlEventTouchUpInside];
    [rightButton setBackgroundImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal];
    
    UIBarButtonItem *rightBarButton=[[UIBarButtonItem alloc]initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem=rightBarButton;
   
    UIButton *leftBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *img1 = [UIImage imageNamed:@"b_kefu"];
    leftBtn.frame=CGRectMake(0, 0, img1.size.width, img1.size.height);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"b_kefu"] forState:UIControlStateNormal];
    
    [leftBtn addTarget:self action:@selector(keFuClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftBarBtn=[[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem=leftBarBtn;
    
    
    [self data];
    
    // Do any additional setup after loading the view.
}
//- (void)tongzhi:(NSNotification *)text{
//    
//    NSLog(@"通知    %@",text.userInfo[@"textOne"]);
//    
//    NSLog(@"－－－－－接收到通知------");
//    
//    
//    [[NSNotificationCenter defaultCenter]removeObserver:self];
//    
//}

- (void)keFuClick{
    M_MineHelpZXViewController *vc = [[M_MineHelpZXViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (void)creationView{
//    [self.view removeFromSuperview];
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    //显示滚动条
    style.showLine = YES;
    //124 129 135
    // 颜色渐变
    style.gradualChangeTitleColor = YES;
 
    style.scrollTitle = YES;
    style.autoAdjustTitlesWidth = YES;
    style.adjustCoverOrLineWidth = YES;
    style.normalTitleColor = [UIColor colorWithRed:114 / 255.0f green:114 / 255.0f blue:114 / 255.0f alpha:1];
    //251 72 197
    style.selectedTitleColor = [UIColor colorWithRed:251 / 255.0f green:72 / 255.0f blue:197 / 255.0f alpha:1];
    style.scrollLineColor = [UIColor colorWithRed:251 / 255.0f green:72 / 255.0f blue:197 / 255.0f alpha:1];
    style.segmentHeight = 40;
    
    __weak typeof(self) weakSelf = self;
    ZJScrollSegmentView *segment = [[ZJScrollSegmentView alloc] initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, 40) segmentStyle:style delegate:self titles:self.titles titleDidClick:^(ZJTitleView *titleView, NSInteger indexID) {
        
        [weakSelf.contentView setContentOffSet:CGPointMake(weakSelf.contentView.bounds.size.width * indexID, 0.0) animated:YES];
        
    }];
    [self.view addSubview:segment];
    segment.backgroundColor = [UIColor whiteColor];
    self.segmentView = segment;
    //  view = self.segmentView;
    
    ZJContentView *content = [[ZJContentView alloc] initWithFrame:CGRectMake(0, 40, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT-40-49) segmentView:self.segmentView parentViewController:self delegate:self];
    
    self.contentView = content;
    [self.view addSubview:self.contentView];
    
    
    
    
}
- (void)data{

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[[UIApplication sharedApplication]keyWindow] animated:YES];
    hud.tag = 500;
    //提示文本
    hud.labelText = @"正在加载...";
    //是否有遮罩
    hud.dimBackground = YES;
    
    
    self.titles = [NSMutableArray array];
    self.arrOfName = [NSMutableArray array];
    self.arrOfID = [NSMutableArray array];

    [[MNetworkHandler sharedInstance]conURL:seltypename
                                networkType:NetWorkPOST
                                     params:nil
                                   delegate:nil
                                    showHUD:NO
                               successBlock:^(id returnData) {
                                   
                                   if ([[returnData objectForKey:@"Status"]intValue] == 200) {
                                       
                                       self.arrOfName = returnData[@"Data"];
                                   
//                                       [self.arrOfID addObject:@"1000"];
//                                       [self.titles addObject:@"热门"];
                                   for (int i = 0; i<self.arrOfName.count; i++) {
                                       
                                       NSString *str = [self.arrOfName[i] objectForKey:@"typename"];
                                       [self.titles addObject:str];
                                       NSString *strID =[NSString stringWithFormat:@"%ld",[[self.arrOfName[i] objectForKey:@"id"]integerValue]];
                                       
                                       [self.arrOfID addObject:strID];
                                       
                                       
                                   }
                                   NSLog(@"DDDDDDDDDDDD%@", self.arrOfID);
                                       [hud removeFromSuperview];
                                   [self creationView];
                                       
                                       
//                                       [PublicFunction showAlert:nil message:@"验证码发送成功" duration:5.0f];
                                       
                                       
                                   }else{
                                       
                                       [hud removeFromSuperview];
                                       
                                       [PublicFunction showAlert:nil message:@"验证码发送失败" duration:1.0f];
                                   }
                                   
                               }
                               failureBlock:^(NSError *error) {
                                   NSLog(@"%@",error);
                                   [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
                                   [hud removeFromSuperview];
                                   
                               }];
    
}
- (void)rightNavItemClick{
    
    M_HomeSouSuoViewController *vc = [[M_HomeSouSuoViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
    
}

#pragma mark ----------------ZJScrollPageViewDelegate---------------------
- (NSInteger)numberOfChildViewControllers {
    return self.titles.count;
}
- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
    
    M_PhotoOneViewController <ZJScrollPageViewChildVcDelegate> *childVc = (M_PhotoOneViewController *)reuseViewController;
    
    if (!childVc) {
        
        childVc = [[M_PhotoOneViewController alloc] init];
//        childVc = self.childVcs[index];
        
//        NSInteger shouYeID = [[PublicFunction getConfigWithKey:@"shouYeID"] integerValue];
        
//        if (shouYeID) {
//
//            childVc.orderStatus = shouYeID;
//            NSLog(@"MMMMMMMMMMMMMM%ld", (long)childVc.orderStatus);
//            [PublicFunction removeConfigWithKey:@"shouYeID"];
//        }else{
//
            childVc.orderStatus = [self.arrOfID[index] integerValue];
            NSLog(@"MMMMMMMMMMMMMM%ld", (long)childVc.orderStatus);
//        }
        
    }
    
    return childVc;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
